package com.coolingme.spring;

import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;

/**
 * Spring提供的计算取解释器
 *
 * @author wangyue
 * @date 2020-09-29 23:42
 */
public class ExpressionParserTest {

    public static void main(String[] args) {
        ExpressionParser parser = new SpelExpressionParser();
        // 12
//        IExpression expression = parser.parseExpression("2 +3 *4 -8 / 4");
        // 18
        Expression expression = parser.parseExpression("(2+3)*4-8/4");

        int value = (Integer) expression.getValue();
        System.out.println("结果为：" + value);
    }

}
